package com.agent.gateway.config;

import com.agent.common.utils.JwtUtils;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

import java.util.Objects;

/**
 * 网关配置
 */
@Configuration
public class GatewayConfig {

    /**
     * 限流解析器配置类
     */
    @Bean
    public KeyResolver remoteAddrKeyResolver() {
        return exchange -> Mono.just(
                Objects.requireNonNull(exchange.getRequest()
                                .getRemoteAddress())
                        .getAddress()
                        .getHostAddress()
        );
    }

    @Bean
    public JwtUtils jwtUtils() {
        return new JwtUtils();
    }
}